<template>
  <div>
    <el-drawer
      :title="title"
      :visible.sync="drawerShow"
      custom-class="wxkj-drawer"
      :destroy-on-close="true"
      size="500px"
    >
      <div class="drawer-content">
        <el-form v-if="dataBody" ref="form" :model="dataBody" class="pl10 pr10" label-width="110px">
          <h2 class="f16 form-title">企业HR信息</h2>
          <el-form-item label="联系人">
            <span>{{ dataBody.name }}</span>
          </el-form-item>
          <el-form-item label="联系人手机号">
            <span>{{ dataBody.mobile }}</span>
          </el-form-item>
          <el-form-item label="联系人邮箱">
            <span>{{ dataBody.enMail }}</span>
          </el-form-item>
          <el-form-item label="称呼">
            <span>{{ dataBody.callName }}</span>
          </el-form-item>
          <!-- 客户要求隐藏
        <el-form-item label="身份证号">
          <span>{{ dataBody.idNumber }}</span>
        </el-form-item>

        <el-form-item label="身份证国徽面">
          <div class="fl upload-wrap">
            <el-image :src="positiveFile?positiveFile:require('@/assets/images/card1.png')" :preview-src-list="[positiveFile]" class="avatar" />
          </div>
        </el-form-item>
        <el-form-item label="身份证人像面">
          <div class="fl upload-wrap" prop="idPic">
            <el-image :src="backFile?backFile:require('@/assets/images/card2.png')"  :preview-src-list="[backFile]" class="avatar" />
          </div>
        </el-form-item>
        -->
          <h2 class="f16 form-title">企业基本信息</h2>
          <el-form-item label="企业LOGO" prop="idPic">
            <div class="upload-wrap">
              <el-image :src="dataBody.enLogo_dictText" :preview-src-list="[dataBody.enLogo_dictText]" class="avatar" />
            </div>
          </el-form-item>
          <el-form-item label="企业名称">
            <span>{{ dataBody.enName }}</span>
          </el-form-item>
          <el-form-item label="专场">
            <span>{{ getDeptText(dataBody.affUnit) }}</span>
          </el-form-item>
          <el-form-item label="企业所在地">
            <span>{{ dataBody.enAddress_dictText }}</span>
          </el-form-item>
          <el-form-item label="详细地址：" prop="enLocation">
            <span>{{ dataBody.enLocation }}</span>
          </el-form-item>
          <el-form-item label="所属行业">
            <span>{{ dataBody.enTrade_dictText }}</span>
          </el-form-item>
          <el-form-item label="企业性质">
            <span>{{ dataBody.enNature }}</span>
          </el-form-item>
          <el-form-item label="对公账号">
            <span>{{ dataBody.account }}</span>
          </el-form-item>
          <el-form-item label="开户行全称">
            <span>{{ dataBody.bankName }}</span>
          </el-form-item>
          <el-form-item label="营业执照">
            <div class="upload-wrap">
              <el-image v-for="(item,index) in license" :key="index" :preview-src-list="license" :src="item" class="avatar" />
            </div>
          </el-form-item>
          <h2 v-if="isExamine||dataBody.state!=1" class="f16 form-title">注册信息审核</h2>
          <el-form-item v-if="isExamine" label="审核结果" prop="idPic"> <!-- v-if="dataBody.state" -->
            <el-radio-group v-model="form.state">
              <el-radio label="0">通过</el-radio>
              <el-radio label="2">不通过</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item v-if="isExamine" label="备注"> <!-- v-if="dataBody.state" -->
            <el-input v-model="form.remark" placeholder="选填" />
          </el-form-item>
          <el-form-item v-if="dataBody.state!=1" label="审核结果">
            <span>{{ dataBody.state|stateFilter }}</span>
          </el-form-item>
          <el-form-item v-if="dataBody.state!=1" label="备注">
            <span>{{ dataBody.remark }}</span>
          </el-form-item>
          <h2 v-if="!dataBody.state" class="f16 form-title">招聘数据概况统计</h2>
          <el-row v-if="!dataBody.state">
            <el-col :span="6"><div class="grid-content bg-purple" />
              <h2 class="f14 text-center">在招职位</h2>
              <p class="text-center f18 text-blue">{{ dataBody.postNum?dataBody.postNum:'-' }}</p>
            </el-col>
            <el-col :span="6"><div class="grid-content bg-purple-light" />
              <h2 class="f14 text-center">今日发布职位</h2>
              <p class="text-center f18 text-blue">{{ dataBody.dayPublishCount?dataBody.dayPublishCount:'-' }}</p>
            </el-col>
            <el-col :span="6"><div class="grid-content bg-purple" />
              <h2 class="f14 text-center">本月发布职位</h2>
              <p class="text-center f18 text-blue">{{ dataBody.monthPublishCount?dataBody.monthPublishCount:'-' }}</p>
            </el-col>
            <el-col :span="6"><div class="grid-content bg-purple-light" />
              <h2 class="f14 text-center">本年度发布职位</h2>
              <p class="text-center f18 text-blue">{{ dataBody.yearPublishCount?dataBody.yearPublishCount:'-' }}</p>
            </el-col>
          </el-row>
          <el-row v-if="!dataBody.state">
            <el-col :span="6"><div class="grid-content bg-purple" />
              <h2 class="f14 text-center">简历投递量</h2>
              <p class="text-center f18 text-blue">{{ dataBody.deliverNum?dataBody.deliverNum:'-' }}</p>
            </el-col>
            <el-col :span="6"><div class="grid-content bg-purple-light" />
              <h2 class="f14 text-center">反馈率</h2>
              <p class="text-center f18 text-blue">{{ dataBody.feedAck?dataBody.feedAck:'-' }}</p>
            </el-col>
            <el-col :span="6"><div class="grid-content bg-purple" />
              <h2 class="f14 text-center">面试率</h2>
              <p class="text-center f18 text-blue">{{ dataBody.interviewRate?dataBody.interviewRate:'-' }}</p>
            </el-col>
            <el-col :span="6"><div class="grid-content bg-purple-light" />
              <h2 class="f14 text-center">入职率</h2>
              <p class="text-center f18 text-blue">{{ dataBody.inductionRate?dataBody.inductionRate:'-' }}</p>
            </el-col>
          </el-row>
          <div v-if="isExamine" class="drawer-form-buttom-group">
            <el-button type="primary" @click="examineAction">确定</el-button>
            <el-button @click="drawerShow = false">取消</el-button>
          </div>
          <div v-else class="drawer-form-buttom-group">
            <el-button type="primary" @click="drawerShow = false">确定</el-button>
          </div>
        </el-form>
      </div>
    </el-drawer>
  </div>
</template>
<script>
import { companyView, companyExam } from '@/api/vip-company'
// import { getImg } from '@/utils/privateImg'
import { sign } from '@/api/common'
export default {
  filters: {
    stateFilter(e) {
      if (!e) {
        return '通过'
      } else if (e == 1) {
        return '未审核'
      } else {
        return '未通过'
      }
    }
  },
  props: {
    isExamine: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      drawerShow: false,
      title: '',
      dataBody: null,
      form: {
        state: '0',
        remark: ''
      },
      positiveFile: '',
      backFile: '',
      license: [],
      deptOptions: [
        { label: '无', value: '0' },
        { label: '河南省工信厅', value: 'gxt' }
      ]
    }
  },
  watch: {
    drawerShow(bl) {
      if (!bl) {
        this.dataBody = null
      }
    }
  },
  methods: {
    show(title, rowData) {
      this.title = title
      this.drawerShow = true
      companyView({ id: rowData.id }).then(response => {
        this.dataBody = response.result
        // 私有库图片
        // getImg(this.dataBody.positiveFileid).then(res => {
        //   this.src = res
        // })
        // // 身份证正面
        // sign({ fileId: this.dataBody.positiveFileid }).then(res => {
        //   this.positiveFile = this.dataBody.positiveFileid_dictText + '?sign=' + res.result
        // })
        // // 身份证反面
        // sign({ fileId: this.dataBody.backFileid }).then(res => {
        //   this.backFile = this.dataBody.backFileid_dictText + '?sign=' + res.result
        // })

        // 身份证头像
        console.log('========>身份证国徽', this.dataBody.positiveFileid)
        const dataBody = this.dataBody

        if (dataBody.positiveFileid == '' || dataBody.positiveFileid == null) {
          // this.positiveFile='@/assets/images/card1.png'
          // this.positiveFile='https://admin.huanghehr.com/assets/images/card1.png'
        } else {
          sign({ fileId: this.dataBody.positiveFileid }).then(res => {
            this.positiveFile = this.dataBody.positiveFileid_dictText + '?sign=' + res.result
          })
        }

        console.log('========>身份证人像', dataBody.backFileid)
        if (dataBody.backFileid == '' || dataBody.backFileid == null) {
          // this.backFile='@/assets/images/card2.png'
        } else {
          sign({ fileId: this.dataBody.backFileid }).then(res => {
            this.backFile = this.dataBody.backFileid_dictText + '?sign=' + res.result
          })
        }

        const ls = this.dataBody.license.split(',')
        const lds = this.dataBody.license_dictText.split(',')
        // 营业执照
        this.license = []
        ls.forEach((item, index) => {
          sign({ fileId: item }).then(res => {
            this.license.push(lds[index] + '?sign=' + res.result)
          })
        })
      })
      console.log(this.positiveFile)
    },
    getDeptText(dept) {
      const items = this.deptOptions.filter(item => {
        return item.value === dept
      })
      return items[0]?.label
    },
    examineAction() {
      console.log(this.form)
      companyExam(Object.assign(this.form, { id: this.dataBody.id })).then(response => {
        this.$message({
          type: 'success',
          message: '审核完成!'
        })
        this.dataBody.state = this.form.state
        this.dataBody.remark = this.form.remark
        this.drawerShow = false
        this.$emit('refresh')
      })
    }
  }
}
</script>

<style lang="scss" scoped>
  .form-title{
    margin: 15px 0 25px 0;
  }
  .upload-wrap{
    .el-upload-list--picture-card::after{
      display: block;
      content: "";
      clear: both;
    }
    ::v-deep .el-upload-list--picture-card{
      margin-bottom: -10px;
    }
    ::v-deep .el-upload-list--picture-card .el-upload-list__item{
      width: 100px;
      height: 100px;
      margin-bottom: 10px;
      float: left;
      position: relative;
      .el-progress-circle{
        display: none !important;
      }
    }
    ::v-deep .el-upload{
      width: 100px;
      height: 100px;
      border: 1px dashed #d9d9d9;
      cursor: pointer;
      position: relative;
      border-radius: 6px;
      background: none;
      .uploader-item-icon {
        display: block;
        font-size: 28px;
        color: #8c939d;
        width: 100px;
        height: 100px;
        line-height: 100px;
        text-align: center;
      }
    }
    .tips{
      margin: 0;
      margin-top: 10px;
      line-height: 24px;
    }
  }
  .avatar {
    width: 100px;
    height: 100px;
    margin-bottom: 10px;
    margin-right: 10px;
    float: left;
    display: block;
  }
</style>
